package cn.zkteco.doordu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.zkteco.doordu.R;
import cn.zkteco.doordu.model.Cmd;

/**
 * Created by Administrator on 2017/10/18.
 */

public class CmdAdapter extends BaseAdapter {

    Context context;
    List<Cmd> list;
    LayoutInflater inflater;

    public CmdAdapter(Context context,List<Cmd> list){
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {

        Holder holder;

        if(view==null){
            holder = new Holder();
            view = inflater.inflate(R.layout.item_cmd,parent,false);
            holder.command = view.findViewById(R.id.tv_command);
            holder.description = view.findViewById(R.id.tv_description);
            view.setTag(holder);
        }else{
            holder = (Holder) view.getTag();
        }

        holder.command.setText(list.get(position).command);
        if (list.get(position).status == 0){
            holder.description.setText(list.get(position).type+"成功");
        }else{
            holder.description.setText(list.get(position).type+"失败");
        }
        return view;
    }


    static class Holder{
        TextView command,description;
    }
}
